package instrumenter;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class SysLogger {
	
	public static String output = "trace.log";
	
	/** writes an integer to a file.
	 * This integer represents a bytecode line number and will be appended to the file referred @field output
	 * */
	public static void preLogger(int i){
		BufferedWriter out;
		try {
			out = new BufferedWriter(new FileWriter(output, true));
			out.append("<node>"+System.lineSeparator()+"<bytecode>");
			out.append(i+"");
			out.append("</bytecode>"+System.lineSeparator()+"<executionType>PRE</executionType>"+System.lineSeparator()+"</node>");
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void postLogger(int i){
		BufferedWriter out;
		try {
			out = new BufferedWriter(new FileWriter(output, true));
			out.append("<node>"+System.lineSeparator()+"<bytecode>");
			out.append(i+"");
			out.append("</bytecode>"+System.lineSeparator()+"<executionType>POST</executionType>"+System.lineSeparator()+"</node>");
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/*
	public static void log(){
		FileWriter out;
		System.out.println("printtttt");
		try {
			out = new FileWriter(output, true);
			out.write(123456);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	
	public static void main(String[] args) {
		SysLogger.log(59876);
	}
	*/
}
